import vtk

filename = "arm1.stl"
 
reader = vtk.vtkSTLReader()
reader.SetFileName(filename)
 
mapper = vtk.vtkPolyDataMapper()
if vtk.VTK_MAJOR_VERSION <= 5:
    mapper.SetInput(reader.GetOutput())
else:
    mapper.SetInputConnection(reader.GetOutputPort())

actor = vtk.vtkActor()
actor.SetMapper(mapper)
actor.SetPosition(0, 0, 0)
cone = vtk.vtkConeSource ()
cone.SetHeight( 100.0 )
cone.SetRadius( 20.0 )
cone.SetResolution( 10 )

coneMapper = vtk.vtkPolyDataMapper()
coneMapper.SetInputConnection(cone.GetOutputPort())

coneActor = vtk.vtkActor()
coneActor.SetMapper(coneMapper)
coneActor.SetPosition(0, 0, 0)
coneActor.GetProperty().SetColor(1, 0, 0)
coneActor.GetProperty().SetDiffuse(0.7)
coneActor.GetProperty().SetSpecular(0.4)
coneActor.GetProperty().SetSpecularPower(20)

property = vtk.vtkProperty()
property.SetColor(0, 0, 1)
property.SetDiffuse(0.7)  
property.SetSpecular(0.4)
property.SetSpecularPower(20)  #散射与反射率

coneActor2 = vtk.vtkActor()
coneActor2.SetMapper(coneMapper)
coneActor2.SetProperty(property)
coneActor2.SetPosition(0, 0, 80)  #中心位置
coneActor2.SetOrigin(0,0,0)

# Create a rendering window and renderer
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.SetSize(1000, 500) #建立窗口
renWin.AddRenderer(ren)

 
# Create a renderwindowinteractor
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)

# Assign actor to the renderer
ren.AddActor(actor)
ren.AddActor(coneActor)
ren.AddActor(coneActor2)

camera = ren.GetActiveCamera()
camera.SetPosition(300,100,80)  # 设置相机位置
camera.SetFocalPoint(0, 100, 0)  # 设置焦距（即观察目标的位置）
camera.SetViewUp(0,0,1)    

# Enable user interface interactor
iren.Initialize()
renWin.Render()
iren.Start()
